package com.zrwl.poscloud.core.restapi.admin.baseInfo;

import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.DeptAdminRService;
import com.zrwl.poscloud.xo.vo.DeptAdminRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 部门权限 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2022-03-10
 */
@RestController
@Api(value = "部门权限相关接口", tags = {"部门权限相关接口"})
@RequestMapping("/deptAdminR")
@Slf4j
public class DeptAdminRRestApi {
    @Autowired
    private DeptAdminRService deptAdminRService;

    @AuthorityVerify
    @ApiOperation(value = "获取部门权限列表", notes = "获取部门权限列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody DeptAdminRVO deptAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取部门权限列表: {}", deptAdminRVO);
        return ResultUtil.successWithData(deptAdminRService.getPageList(deptAdminRVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取部门权限列表", notes = "获取部门权限列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody DeptAdminRVO deptAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取部门权限列表: {}", deptAdminRVO);
        return ResultUtil.successWithData(deptAdminRService.getAllList(deptAdminRVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增部门权限")
    @ApiOperation(value = "新增部门权限", notes = "新增部门权限", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody DeptAdminRVO deptAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增部门权限: {}", deptAdminRVO);
        return deptAdminRService.add(deptAdminRVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改部门权限")
    @ApiOperation(value = "修改部门权限", notes = "修改部门权限", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody DeptAdminRVO deptAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改部门权限: {}", deptAdminRVO);
        return deptAdminRService.edit(deptAdminRVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除部门权限")
    @ApiOperation(value = "删除部门权限", notes = "删除部门权限", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody DeptAdminRVO deptAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除部门权限: {}", deptAdminRVO);
        return deptAdminRService.delete(deptAdminRVO);
    }

    @AuthorityVerify
    @ApiOperation(value = "获取管理员拥有部门权限列表", notes = "获取管理员拥有部门权限列表", response = String.class)
    @PostMapping("/getAdminOwnDeptRoleListForTransferTree")
    public String getAdminOwnDeptRoleListForTransferTree(@RequestBody DeptAdminRVO deptAdminRVO) {
        log.info("获取管理员拥有部门权限列表: {}", deptAdminRVO);
        return ResultUtil.successWithData(deptAdminRService.getAdminOwnDeptRoleListForTransferTree(deptAdminRVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取管理员未拥有部门权限列表", notes = "获取管理员未拥有部门权限列表", response = String.class)
    @PostMapping("/getAdminNotOwnDeptRoleListForTransferTree")
    public String getAdminNotOwnDeptRoleListForTransferTree(@RequestBody DeptAdminRVO deptAdminRVO) {
        log.info("获取管理员未拥有部门权限列表: {}", deptAdminRVO);
        return ResultUtil.successWithData(deptAdminRService.getAdminNotOwnDeptRoleListForTransferTree(deptAdminRVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "修改管理员部门权限")
    @ApiOperation(value = "修改管理员部门权限", notes = "修改管理员部门权限", response = String.class)
    @PostMapping("/editAdminDeptRoleForTransferTree")
    public String editAdminDeptRoleForTransferTree(@RequestBody DeptAdminRVO deptAdminRVO) {
        log.info("修改管理员部门权限: {}", deptAdminRVO);
        return deptAdminRService.editAdminDeptRoleForTransferTree(deptAdminRVO);
    }

    @AuthorityVerify
    @ApiOperation(value = "获取管理员部门权限列表", notes = "获取管理员部门权限列表", response = String.class)
    @PostMapping("/getAdminOwnDeptRoleList")
    public String getAdminOwnDeptRoleList(@RequestBody DeptAdminRVO deptAdminRVO) {
        log.info("获取管理员未拥有部门权限列表: {}", deptAdminRVO);
        return ResultUtil.successWithData(deptAdminRService.getAdminOwnDeptRoleList(deptAdminRVO,new HashMap()));
    }

    @AuthorityVerify
    @OperationLogger(value = "修改管理员部门权限")
    @ApiOperation(value = "修改管理员部门权限", notes = "修改管理员部门权限", response = String.class)
    @PostMapping("/editAdminDeptRole")
    public String editAdminDeptRole(@RequestBody DeptAdminRVO deptAdminRVO) {
        log.info("修改管理员部门权限: {}", deptAdminRVO);
        return deptAdminRService.editAdminDeptRole(deptAdminRVO);
    }

}
